/*公共common.js组件*/
$(function(){
    //iframe内点击，也能使最外层页面的用户下拉框消失
    $(document).click(function(){
        if(window.parent.closeUserOption){
            window.parent.closeUserOption();
        }
    });
});
/**
 * 网络延迟状态下，防止表单重复提交
 * @param btnId  按钮Id
 * @param formId  表单Id
 */
function preventSubmit(formId,btnId){
    if(formId == null || formId == ""){
        $("#"+btnId).linkbutton('disable');
        $("#"+btnId).unbind("click");
        return;
    }
    if($('#'+formId).form("validate")){
        $("#"+btnId).linkbutton('disable');
        $("#"+btnId).unbind("click");
    }
}

/**
 * 清空form
 * @param id form的id
 */
function clearForm(id){
    var lis = $('#' + id).find("input[type='text']");
    lis.each(function(i, dom){
        $(dom).val("");
    });

    var lis = $('#' + id).find("input[type='password']");
    lis.each(function(i, dom){
        $(dom).val("");
    });
    //清空表单
    $('#' + id).form('clear');
}

/***
 * 动态刷新页面
 * @param dgId
 */
function refreshPageNumber(dgId) {
    //获取dataGrid的列表对象属性
    var $datagrid = $("#" + dgId).datagrid("options");
    if ($datagrid != undefined) {
        $datagrid.pageNumber = 1;
    }
    //获取dataGrid的分页对象
    var $getPager = $("#" + dgId).datagrid('getPager');
    var $pagination = $($getPager).pagination("options");
    if ($pagination != undefined) {
        $pagination.pageNumber = 1;
    }
}

/**
 * 限制输入字段的长度
 */
function limitFieldLength(){
    $(".easyui-textbox").each(function(){
        var data_options = $(this).attr("data-options");
        if(data_options){
            var matchs = data_options.match(/length\[1,(\d*)\]/);
            if(matchs){
                $(this).textbox("textbox").attr("maxlength", matchs[1] - 0 + 1);
            }else{
                $(this).textbox("textbox").attr("maxlength", 20);
            }
        }else{
            $(this).textbox("textbox").attr("maxlength", 20);
        }
    });
}

/**
 * 服务器JSON对象
 * @param obj
 */
function messager(obj){
    var title = ""
    //成功编码
    if(obj.code == 'PC_200'){
        title = '操作成功';
    }else{
        title = '操作失败';
    }
    $.messager.show({ title:title, msg: obj.message, timeout:3000, showType:"slide" });
}


/**
 * 设置睡眠（单位毫秒）
 * @param n
 */
function sleep(n) {
    var start = new Date().getTime();
    while (true) {
        if (new Date().getTime() - start > n) {
            break;
        }
    }
}



/**
 * 字符串转换成JSON对象
 * @param {Object} data
 * @autour 谢泽鹏
 */
function toJson(data) {
    return eval('('+data+')');
}

/***
 * 字符串转换成Array对象
 * @param {Object} data
 * @autour 谢泽鹏
 */
function toArray(data){
    return eval(data);
}


/**
 * 判断是否是IE浏览器
 * @returns {boolean}
 */
function isIE() {
    //取得浏览器的userAgent字符串
    var userAgent = navigator.userAgent;
    ////判断是否IE<11浏览器
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
    //判断是否IE的Edge浏览器
    var isEdge = userAgent.indexOf("Edge") > -1 && !isIE;
    var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
    if(isIE) {
        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
        reIE.test(userAgent);
        var fIEVersion = parseFloat(RegExp["$1"]);
        if(fIEVersion == 7) {
            return true;
        } else if(fIEVersion == 8) {
            return true;
        } else if(fIEVersion == 9) {
            return true;
        } else if(fIEVersion == 10) {
            return true;
        } else {
            //IE版本<=7
            return true;
        }
    } else if(isEdge) {
        //edge
        return false;
    } else if(isIE11) {
        //IE11
        return true;
    }else{
        //不是ie浏览器
        return false;
    }
}

/**
 * 判断是否为IE包含IE11
 */
function isIEAll(){
    if (!!window.ActiveXObject || "ActiveXObject" in window){
        return true;
    }else{
        return false;
    }
}


/**
 * EasyUI DataGrid根据字段动态合并单元格
 * 参数 tableID 要合并table的id
 * 参数 colList 要合并的列,用逗号分隔(例如："name,department,office");
 **/
function mergeCellsByField(tableID, colList) {
    var ColArray = colList.split(",");
    var tTable = $("#" + tableID);
    var TableRowCnts = tTable.datagrid("getRows").length;
    var tmpA;
    var tmpB;
    var PerTxt = "";
    var CurTxt = "";

    for (var j = ColArray.length - 1; j >= 0; j--) {
        PerTxt = "";
        tmpA = 1;
        tmpB = 0;

        for (var i = 0; i <= TableRowCnts; i++) {
            if (i == TableRowCnts) {
                CurTxt = "";
            }
            else {
                CurTxt = tTable.datagrid("getRows")[i][ColArray[j]];
            }
            if (PerTxt == CurTxt) {
                tmpA += 1;
            }
            else {
                tmpB += tmpA;

                tTable.datagrid("mergeCells", {
                    index: i - tmpA,
                    field: ColArray[j],//合并字段
                    rowspan: tmpA,
                    colspan: null
                });
                tTable.datagrid("mergeCells", { //根据ColArray[j]进行合并
                    index: i - tmpA,
                    field: "Ideparture",
                    rowspan: tmpA,
                    colspan: null
                });

                tmpA = 1;
            }
            PerTxt = CurTxt;
        }
    }
}


/**
 * 设置容器自动宽
 * @param {} percent 百分比率
 * @return {}
 */
function fixWidth(percent) {
    //这里你可以自己做调整
    return parseInt(document.body.clientWidth * percent);
}

/***
 * 生成随机验证码
 * @autour 谢泽鹏
 */
function createCode() {
    var code = "";
    //验证码的长度
    var codeLength = 4;
    //所有候选组成验证码的字符，当然也可以用中文的
    var selectChar = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
    for (var i = 0; i < codeLength; i++) {
        var charIndex = Math.floor(Math.random() * 36);
        code += selectChar[charIndex];
    }
    document.getElementById("valiCode").innerHTML = code;
}

/**
 * 获取当前时间月
 * @param date
 * @returns {string}
 */
function getFirstDay(date){
    var y = date.getFullYear();
    var m = date.getMonth()+1;
    var d = date.getDate();
    return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
}

/**
 * 改变主题样式
 * @param themeName
 */
var changeTheme = function(themeStyle) {
    $.messager.confirm("系统提示", "确定更换系统皮肤为 " + themeStyle + " 样式吗？", function(r) {
        if (r) {
            $.ajax({
                url: CONTEXT_PATH + '/sysConfig/sysSetting.do',
                data: {themeStyle: themeStyle},
                dataType: 'json',
                success: function(data){
                    if(data.code == 'PC_200'){
                        window.location.reload();
                    }
                }
            });
        }
    });
};


function getCurDay(date){
    var y = date.getFullYear();
    var m = date.getMonth()+1;
    var d = date.getDate();
    return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
}

function myparser(s){
    if (!s) return new Date();
    var ss = (s.split('-'));
    var y = parseInt(ss[0],10);
    var m = parseInt(ss[1],10);
    var d = parseInt(ss[2],10);
    if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
        return new Date(y,m-1,d);
    } else {
        return new Date();
    }
}

/***
 * 字验证数据有效性
 * @param type  数据验证方式
 * @param ctrl  验证控件ID
 * @autour 谢泽鹏
 */
function validate(type, ctrl) {
    var reg = "";
    var val = jQuery("#"+ctrl).val();
    switch(flag) {
        case "ISNOTNULL":
            reg = /(^\S)|(\S$)/;
            if(!val.match(reg))
            {
                $.messager.alert("系统提示","该项不能为空,请输入内容信息！",'info');
                jQuery("#"+ctrl).focus();
            }
            break;
        case "INTEGER":
            reg = /^[\-\+]?\d+$/;
            if(!val.match(reg))
            {
                $.messager.alert("系统提示","输入数据有误,请输入正整数！",'info');
                jQuery("#"+ctrl).focus();
            }
            break;
        case "ISNUMBER":
            reg = /^[\-\+]?(([0-9]+)([\.,]([0-9]+))?|([\.,]([0-9]+))?)$/;
            if(!val.match(reg))
            {
                $.messager.alert("系统提示","输入数据有误,请输入数字！",'info');
                jQuery("#"+ctrl).focus();
            }
            break;
        case "EMAIL":
            reg = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
            if(!val.match(reg))
            {
                $.messager.alert("系统提示","输入电子邮件有误,请重新输入！",'info');
                jQuery("#"+ctrl).focus();
            }
            break;
        case "PHONE":
            reg = /^(\d{3,4}\-)?\d{7,8}$/i;
            if(!val.match(reg))
            {
                $.messager.alert("系统提示","输入电话号码有误,请重新输入！",'info');
                jQuery("#"+ctrl).focus();
            }
            break;
        case "ADDRESSPHONE":
            reg = /^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/;
            if(!val.match(reg))
            {
                $.messager.alert("系统提示","输入座机号码有误,请重新输入！",'info');
                jQuery("#"+ctrl).focus();
            }
            break;
        case "IPV4":
            reg = /^((([01]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))[.]){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))$/;
            if(!val.match(reg))
            {
                $.messager.alert("系统提示","输入IP地址有误,请重新输入！",'info');
                jQuery("#"+ctrl).focus();
            }
            break;
        case "URL":
            reg = /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i;
            if(!val.match(reg))
            {
                $.messager.alert("系统提示","输入URL地址有误,请重新输入！",'info');
                jQuery("#"+ctrl).focus();
            }
            break;
        case "QQ":
            reg = /^[1-9]\d{4,8}$/;
            if(!val.match(reg))
            {
                $.messager.alert("系统提示","输入QQ号码有误,请重新输入！",'info');
                jQuery("#"+ctrl).focus();
            }
            break;
        case "IDCARD":
            reg = new RegExp("^[0-9]{15}$");
            var reg1 = new RegExp("^[0-9]{18}$");
            if(!jval.match(reg)&&!val.match(reg1))
            {
                $.messager.alert("系统提示","输入身份证号有误,请重新输入！",'info');
                jQuery("#"+ctrl).focus();
            }
            break;
        case "LENGTH":

            break;
    }
}

/**
 * 扩展Date，format方法
 * @author 丁奕
 * @param format
 * @returns {*}
 */
Date.prototype.format = function (mask) {
    var d = this;
    var zeroize = function (value, length)
    {
        if (!length) length = 2;
        value = String(value);
        for (var i = 0, zeros = ''; i < (length - value.length); i++)
        {
            zeros += '0';
        }
        return zeros + value;
    };
    var result = mask.replace(/"[^"]*"|'[^']*'|\b(?:d{1,4}|m{1,4}|yy(?:yy)?|([hHMstT])\1?|[lLZ])\b/g, function ($0)
    {
        switch ($0)
        {
            case 'd': return d.getDate();
            case 'dd': return zeroize(d.getDate());
            case 'ddd': return ['Sun', 'Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat'][d.getDay()];
            case 'dddd': return ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][d.getDay()];
            case 'M': return d.getMonth() + 1;
            case 'MM': return zeroize(d.getMonth() + 1);
            case 'MMM': return ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()];
            case 'MMMM': return ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][d.getMonth()];
            case 'yy': return String(d.getFullYear()).substr(2);
            case 'yyyy': return d.getFullYear();
            case 'h': return d.getHours() % 12 || 12;
            case 'hh': return zeroize(d.getHours() % 12 || 12);
            case 'H': return d.getHours();
            case 'HH': return zeroize(d.getHours());
            case 'm': return d.getMinutes();
            case 'mm': return zeroize(d.getMinutes());
            case 's': return d.getSeconds();
            case 'ss': return zeroize(d.getSeconds());
            case 'l': return zeroize(d.getMilliseconds(), 3);
            case 'L': var m = d.getMilliseconds();
                if (m > 99) m = Math.round(m / 10);
                return zeroize(m);
            case 'tt': return d.getHours() < 12 ? 'am' : 'pm';
            case 'TT': return d.getHours() < 12 ? 'AM' : 'PM';
            case 'Z': return d.toUTCString().match(/[A-Z]+$/);
            // Return quoted strings with the surrounding quotes removed
            default: return $0.substr(1, $0.length - 2);
        }
    });
    return result;
}

/**
 *  金额格式化
 *  保留两位小数（四舍五入, 123213.56）
 **/
function formatmoney(s){
    if(null == s || "" == s || undefined == s){
        return "0.00";
    }
    //保留两位小数 四舍五入
    var num = new Number(s);
    s = num.toFixed(2);

    //格式资金分隔符
    s = s.replace(/^(\d*)$/,"$1.");
    s = (s+"00").replace(/(\d*\.\d\d)\d*/,"$1");
    s = s.replace(".",",");

    var re = /(\d)(\d{3},)/;
    while(re.test(s)){
        s = s.replace(re,"$1,$2");
    }
    s = s.replace(/,(\d\d)$/,".$1");
    return s.replace(/^\./,"0.");
}


/**
 *  金额格式化
 *  保留两位小数（四舍五入，新增分隔符号  111,223,233）
 **/
function formatMoneySpilt(s){
    if(null == s || "" == s || undefined == s){
        return "0.00";
    }
    //保留两位小数 四舍五入
    var num = new Number(s);
    s = num.toFixed(2);

    //格式资金分隔符
    s = s.replace(/^(\d*)$/,"$1.");
    s = (s+"00").replace(/(\d*\.\d\d)\d*/,"$1");
    s = s.replace(".",".");

    var re = /(\d)(\d{3},)/;
    while(re.test(s)){
        s = s.replace(re,"$1,$2");
    }
    s = s.replace(/,(\d\d)$/,".$1");
    return s.replace(/^\./,"0.");
}


/**
 * 转换日期对象为日期字符串
 * @param l long值
 * @param pattern 格式字符串,例如：yyyy-MM-dd hh:mm:ss
 * @return 符合要求的日期字符串
 */
function getFormatDate(date, pattern) {
    if (date == undefined) {
        date = new Date();
    }
    if (pattern == undefined) {
        pattern = "yyyy-MM-dd HH:mm:ss";
    }
    return date.format(pattern);
}


function getSmpFormatDate(date, isFull) {
    var pattern = "";
    if (isFull == true || isFull == undefined) {
        pattern = "yyyy-MM-dd HH:mm:ss";
    } else {
        pattern = "yyyy-MM-dd";
    }
    return getFormatDate(date, pattern);
}


/**
 * 时间格式化输出
 * @param date
 * @returns {*}
 */
function formatDate(date){
    if(undefined == date || "" == date){
        return "-";
    }
    var newTime = "";
    if(date.toString().length > 19){
        date = date.toString().substr(0, 19);
        newTime = new Date(date.replace("-", "/").replace("-", "/"));
    }else{
        newTime = new Date(date);
    }
    var month = 0;
    var date1 = 0;
    var hours = 0;
    var minutes = 0;
    var seconds = 0;
    if((newTime.getMonth() + 1) < 10) {
        month = "0" + (newTime.getMonth() + 1);
    } else{
        month = (newTime.getMonth() + 1);
    }
    if(newTime.getDate() < 10){
        date1 = "0" + newTime.getDate();
    }else{
        date1 = newTime.getDate();
    }
    if(newTime.getHours()<10){
        hours = "0" + newTime.getHours();
    }else{
        hours = newTime.getHours();
    }
    if(newTime.getMinutes()<10){
        minutes = "0" + newTime.getMinutes();
    }else{
        minutes = newTime.getMinutes();
    }
    if(newTime.getSeconds()<10){
        seconds = "0" + newTime.getSeconds();
    }else{
        seconds = newTime.getSeconds();
    }
    return  newTime.getFullYear() + "-" + month + "-" + date1+" " + hours + ":" + minutes + ":" + seconds;
}

/**
 * 时间格式化输出,没有时分秒
 * @param date
 * @returns {*}
 */
function formatCalendar(date){
    if(undefined == date || "" == date){
        return "-";
    }
    var newTime = "";
    if(date.toString().length > 19){
        date = date.toString().substr(0, 19);
        newTime = new Date(date.replace("-", "/").replace("-", "/"));
    }else{
        newTime = new Date(date);
    }
    var month = 0;
    var date1 = 0;
    if((newTime.getMonth() + 1) < 10) {
        month = "0" + (newTime.getMonth() + 1);
    } else{
        month = (newTime.getMonth() + 1);
    }
    if(newTime.getDate() < 10){
        date1 = "0" + newTime.getDate();
    }else{
        date1 = newTime.getDate();
    }
    return  newTime.getFullYear() + "-" + month + "-" + date1;
}


/**
 * 前端用切换时间显示方法
 * @author 丁奕
 * @param value
 * @param formatStr "yyyy-MM-dd"形式
 * @param dontfixTime true Or false ,不传入时和传入false时都进行时间修正，传入true时不修正
 * @returns {*}
 */
function formatDatebox(value, formatStr, dontfixTime) {
    if (value == null || value == '') {
        return '';
    }
    if(value.toString().length > 19){
        value = value.toString().substr(0, 19);
    }
    var dt;
    if (value instanceof Date) {
        dt = value;
    } else {
        if(dontfixTime){
            dt = new Date(value.replace(/-/g,"/"));
        }else{
            var localDate = new Date(value);
            var localTime = localDate.getTime();
            //时间修正，整整差了14个小时，时差修正了480分钟，还有360分钟是手动调整的
            var localOffset = (localDate.getTimezoneOffset()- 360)*60*1000 ;
            dt = new Date(localTime + localOffset);
        }
    }
    return dt.format(formatStr); //扩展的Date的format方法(上述插件实现)
}

/**
 * 获取根路径
 * @returns {string}
 */
function getRootPath(){
    var curWwwPath = window.document.location.href;
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    var localhostPaht = curWwwPath.substring(0, pos);
    return localhostPaht;
}


/**
 * 科学计数转换为数字
 * @param num
 * @returns {*}
 */
function scientificToNumber(num) {
    var str = num.toString();
    var reg = /^(\d+)(e)([\-]?\d+)$/;
    var arr, len,
        zero = '';

    /*6e7或6e+7 都会自动转换数值*/
    if (!reg.test(str)) {
        return num;
    } else {
        /*6e-7 需要手动转换*/
        arr = reg.exec(str);
        len = Math.abs(arr[3]) - 1;
        for (var i = 0; i < len; i++) {
            zero += '0';
        }

        return '0.' + zero + arr[1];
    }
}

/**
 * 验证文件是否是图片
 * @param fileName 上传的文件字段的ID
 * @returns {boolean}
 */
function valiImgType(fileNameId){
    var fileName = $("#"+fileNameId).val();
    //获取上传文件名称
    var getfileName = fileName.substring(fileName.lastIndexOf("\\") + 1);
    //获取文件后缀
    var suffix = getfileName.substring(getfileName.lastIndexOf(".") + 1).toUpperCase();
    if("BMP" != suffix && "JPG" != suffix && "JPEG" != suffix && "PNG" != suffix && "GIF" != suffix){
        $.messager.show({ title:'提示', msg: '上传文件格式有误！', timeout:3000, showType:"slide" });
        return false;
    }else{
        return true;
    }
}

/**
 * 弹出加载层
 * @param message  提示消息
 * @param element  提示元素
 */
function loading(message, element) {
    var loadMessage = (null == message || "" == message) ?  "正在加载，请稍候。。。" : message;
    var showElement  = (null == element || "" == element) ? "body" :  $("#" + element);
    $("<div id='" + element + "-datagrid-mask' class=\"datagrid-mask\"></div>").css({ display: "block", width: "100%", height: $(window).height() }).appendTo(showElement);
    $("<div id='" + element + "-datagrid-mask-msg' class=\"datagrid-mask-msg\"></div>").html(loadMessage).appendTo(showElement).css({ display: "block", left: ($(document.body).outerWidth(true) - 190) / 2, top: ($(window).height() - 45) / 2 });
}

/**
 * 取消加载层
 * @param element
 */
function disLoading(element) {
    if(null != element && "" != element){
        $("#" + element).find(".datagrid-mask").remove();
        $("#" + element).find(".datagrid-mask-msg").remove();
        return;
    }
    $(".datagrid-mask").remove();
    $(".datagrid-mask-msg").remove();
}

/**
 * 保存后，成功延时跳转，失败不跳转
 * @param obj
 * @param url
 */
function saveJump(obj,url){
    if((typeof obj != "undefined" || null != obj) && (typeof url != "undefined" || null != url)){
        messager(obj);
        if(obj.code == "PC_200"){
            setTimeout(function() {window.location.href = url;},"3000")
        }
    }
}


/**
 * 检测页面是否关闭，关闭为非正常退出系统
 * @returns {string}
 */
/*window.onbeforeunload = function(){
    var isIE=document.all?true:false;
    if(isIE){//IE浏览器
        var n = window.event.screenX - window.screenLeft;
        var b = n > document.documentElement.scrollWidth-20;
        if(b && window.event.clientY < 0 || window.event.altKey){
            saveUserLog();
        }
    }
    else{
        //其他浏览器
        if(document.documentElement.scrollWidth!=0){
            saveUserLog();
        }
    }
}

/!**
 * 保存用户日志
 *!/
function saveUserLog(){
    var r = window.confirm("您确定要离开系统么？");
    if(r == true){
        $.ajax({
            url: CONTEXT_PATH + "/userLogin/abnormalLogout.do",
            type: "get",
            success: function (data) {
                //console.log("success");
            }
        })
    }
}*/

/*浏览器大小调整时,使得搜索输入框大小保持正常*/
// window.onresize = function(){
//     //
//     var searchToolBar = $(".searchToolBar");
//     if(searchToolBar){
//         var searchToolBarWidth = searchToolBar.width();
//         // if(!searchToolBarWidth){
//         //     searchToolBarWidth = document.body.scrollWidth;
//         // }
//         $(".searchButton").width(searchToolBarWidth *0.95 * 0.5);
//     }
// }


